<script type="text/javascript" language="javascript">
    (function($) {
        /*whatever jQuery stuff*/
        $(function(){
			var queueSize = 0;
			var imgname= new Array();
			var success_file = false;
			var member_id_valid = '<?php echo $dataResult->member_id;?>';		
			$("#Form").validate({
				ignore: "",
				rules: {
					playlist_name: "required",
					playlist_alias: "required"
				},
				showErrors: function(errorMap, errorList){
				var messages='';
					for (var i = 0; i < errorList.length; i++) {					
						messages += '- '+errorList[i].message+'\n';
					}
					if(messages) alert("<?php echo lang('requirement');?>: \n"+"¯¯¯¯¯¯¯¯¯¯ \n"+ messages);
					//this.defaultShowErrors();
				},
				submitHandler: function(e){
					$('.ajax-loading',e).css('visibility','visible');
					if(queueSize > 0){
						$('#file_upload').uploadifyUpload();
					} else { success_file = true; }				
					var interval = setInterval(function() {
					    if(success_file) {
					        clearInterval(interval);
							//Send Form
					        document.forms["Form"].submit();
					    }
					}, 100);
                },
                onfocusout: false,
                onkeyup: false,
				onclick: false,					
                messages: {
					playlist_alias: "<?php echo lang('playlist_alias');?>",			
					playlist_name: "<?php echo lang('playlist_name');?>"			
                }
            });
            
            if(!member_id_valid){
	            /*Images Upload*/				
	            $('#file_upload').uploadify({
	                'uploader'  : '<?php echo base_url();?>uploadify.swf',				
	                'script'    : '<?php echo base_url();?>uploadify.php',
	                'cancelImg' : '<?php echo js_asset_url("uploadify/cancel.png"); ?>',
	                'folder'    : "<?php echo substr($this->temp_folder,0,-1);?>",
	                'fileExt'   : '*.jpg;*.JPG;*.gif;*.GIF;*.png;*.PNG',
	                'fileDesc'  : 'All Files',
					'scriptAccess' : 'always',			
	                'auto'      : false,
	                'multi'     : false,
	                'onComplete' : function(event, ID, fileObj, response, data){
	                    imgname.push(response);
	                },
	                'onAllComplete' : function(event,data) {
						$('<input>').attr({
						    type: 'hidden',
						    id: 'uploadify_store',
						    name: 'uploadify_store',
							value: imgname
						}).appendTo('Form');
						//document.forms["Form"].submit();					
						success_file=true;
	                },
	                'onSelectOnce' : function (event,data) {
	                    queueSize = data.fileCount;
	                },
	                'onCancel' : function (event,ID,fileObj,data) {
	                    queueSize = data.fileCount;
	                }						
	            });					
			}

			//ColorBox Image
			$('a[rel="gallery"]').colorbox();	
			
			//ColorBox Iframe
			$('.search_tools').colorbox({iframe:true, innerWidth:300, innerHeight:600, right:0, opacity:0.4});
        });
    })(jQuery);
</script>
<script type="text/javascript" language="javascript">
/*Add/Remove List*/
function addRemoveList(unique,id,name)
{
	if(id == undefined && name == undefined){ //remove List
		var parentElement = $(unique).closest('ul');
		$(unique).parent().remove();
		if($('li:not(:hidden)',parentElement).length < 1){
			parentElement.find('.first').show();
		}	
	} else { //add List
		var parentElement = $('ul#media_id');
		var value = (unique == "song_id" ? ""+id+"":"video_"+id);
		parentElement.find('.first').hide();
		if($('input[value="'+value+'"]',parentElement).length == 0){
			parentElement.prepend('<li><input type="checkbox" name="default_media_id[]" value="'+value+'" checked="checked"/>&nbsp;'+id+' - '+name+' <a href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);"></a><input type="hidden" name="media_id[]" value="'+value+'" \/><\/li>');
		}		
	}
}		
</script>
<div class="wrap">
 	<div id="icon-index" class="icon32"><br /></div><h2><?php echo ucwords(str_replace('_',' ',$this->uri->segment(1)));?> &raquo; <?php echo ucwords(str_replace('_',' ',$this->uri->segment(2)));?> &raquo; <?php echo lang($this->uri->segment(3));?></h2>
</div>
<div id="wpbody-content">
    <div class="metabox-holder" id="dashboard-widgets">
		<div class="tablenav top">
			<div class="alignleft"><input type="button" value="<?php echo lang('button_back');?>" class="button-primary" onclick="javascript:history.go(-1);"/></div>
		</div>	
            <div class="inside">			
				<form id="Form" method="post" action="" name="Form">
					<table border="0" cellspacing="0" cellpadding="0" class="form-table">
						<tbody>	
						<tr>
							<th scope="row"><?php echo lang('is_publish');?></th>
							<td>
								<input type="radio" name="is_publish" value="1" <?php echo ($dataResult->is_publish == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_publish" value="0" <?php echo ($dataResult->is_publish == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_hilight');?></th>
							<td>
								<input type="radio" name="is_hilight" value="1" <?php echo ($dataResult->is_hilight == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_hilight" value="0" <?php echo ($dataResult->is_hilight == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_recommend');?></th>
							<td>
								<input type="radio" name="is_recommend" value="1" <?php echo ($dataResult->is_recommend == '1' ? 'checked="checked"':'');?>/> <?php echo lang('yes');?>
								<input type="radio" name="is_recommend" value="0" <?php echo ($dataResult->is_recommend == '0' ? 'checked="checked"':'');?>/> <?php echo lang('no');?>
							</td>
						</tr>												
						<tr>
							<th scope="row"><?php echo lang('playlist_alias');?></th>
							<td><input type="text" name="playlist_alias" id="playlist_alias" class="medium-text" value="<?php echo $dataResult->playlist_alias;?>"/></td>
						</tr>																							
						<tr>
							<th scope="row"><?php echo lang('playlist_name');?></th>
							<td><input type="text" name="playlist_name" id="playlist_name" class="regular-text" value="<?php echo $dataResult->playlist_name;?>"/></td>
						</tr>
						<tr>
							<th scope="row"><?php echo lang('playlist_brief');?></th>
							<td><textarea name="playlist_brief" id="playlist_brief" rows="5" class="regular-text"><?php echo $dataResult->playlist_brief;?></textarea></td>
						</tr>
						<tr>
							<th scope="row">
								<?php echo lang('song_relate');?> <a href="<?php echo base_url().'song/playlist_management/search_song';?>" class="tools plus search_tools"></a><br />
								<?php echo lang('video_relate');?> <a href="<?php echo base_url().'song/playlist_management/search_video';?>" class="tools plus search_tools"></a>
							</th>
							<td class="describe">
								<ul id="media_id" class="listItems">
									<?php
									if(!empty($dataPlaylist)):?>
									<li class="first" style="display:none;">
										<?php echo lang('no_media_relate');?>
									</li>
									<?php
									foreach($dataPlaylist as $value):?>
									<li>
										<input type="checkbox" name="default_media_id[]" value="<?php echo $value->media_value;?>" checked="checked"/>
										<?php echo $value->media_id.' - '.$value->media_name;?>
										<a
											href="javascript:void(0)" class="tools minus" onclick="javascript:addRemoveList(this);">
										</a><input type="hidden" name="media_id[]" value="<?php echo $value->media_value;?>" />
									</li>
									<?php endforeach;?>
									<?php
									else:?>
									<li class="first">
										<?php echo lang('no_song_relate');?>
									</li>
									<?php endif;?>
								</ul>
							</td>
						</tr>			
						<tr>
							<th scope="row"><?php echo lang('playlist_image');?></th>
							<td>
								<?php
								if(!empty($dataResult->playlist_file_name)):?>
								<ul class="listImages">
									<li id="playlist_image_id_<?php echo $dataResult->playlist_id;?>">
										<div>
											<?php if($dataResult->member_id == null):?>
												<a href="<?php echo image_asset_url('../uploads/playlist/images/original/'.$dataResult->playlist_file_name.'.'.$dataResult->playlist_file_ext);?>" rel="gallery">
													<?php echo image_asset('../uploads/playlist/images/120x120/'.$dataResult->playlist_file_name.'.'.$dataResult->playlist_file_ext,'',array('width' => 120,'height'=> 120));?>
												</a>											
											<?php else:?>
												<a href="<?php echo image_asset_url('playlist/'.$dataResult->playlist_file_name.'.'.$dataResult->playlist_file_ext);?>" rel="gallery">
													<?php echo image_asset('playlist/'.$dataResult->playlist_file_name.'.'.$dataResult->playlist_file_ext,'',array('width' => 265,'height'=> 120));?>
												</a>												
											<?php endif;?>
										</div>
										<?php if($dataResult->member_id == null):?>
										<a href="<?php echo base_url();?>song/playlist_management/ajax_delete_image/<?php echo $dataResult->playlist_id;?>" class="tools delete deleteImage"></a>
										<?php endif;?>
									</li>
								</ul>
								<?php endif;?>
								<?php if($dataResult->member_id == null):?>
									<input type="file" name="file_upload" id="file_upload"/>
								<?php endif;?>
							</td>
						</tr>																						
						<tr>
							<th scope="row">&nbsp;</th>
							<td><p class="submit"><input type="submit" value="<?php echo lang('button_update');?>" class="button-primary" />&nbsp;<img alt="" class="ajax-loading" src="<?php echo css_asset_url('images/wpspin_light.gif'); ?>" /></p></td>
						</tr>								
						</tbody>
					</table>
					<div class="tablenav bottom"></div>
				</form>
            </div><!-- wpbody inside -->
    </div><!-- wpcontent -->
</div><!-- wpbody-content -->